package com.landary.parameterrplacement.service;

import com.landary.parameterrplacement.entity.MKOrgPost;
import com.landary.parameterrplacement.entity.Post;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author 刘欣
 * @createTime 2023/8/14 9:31
 * @description
 */
@Service
@Slf4j
public class PostParamsConversionService {

    public MKOrgPost psotParamsConversion(Post post) throws Exception {
        if (post == null) {
            throw new Exception("没有获取到门户的岗位信息");
        }
        log.info("================================岗位参数开始转换================================");
        MKOrgPost mkOrgPost = new MKOrgPost();
        if (post.getAvicSimpleTitle() != null) {
            mkOrgPost.setFdId("post:" + post.getAvicSimpleTitle());
            mkOrgPost.setFdNo("post:" + post.getAvicSimpleTitle());
        } else {
            log.error("岗位webservice接口同步AvicSimpleTitle为空");
        }

        if (post.getAvicSimpleTitle() != null) {
            mkOrgPost.setFdName(post.getAvicSimpleTitle());
        } else {
            log.error("岗位webservice接口同步AvicSimpleTitle为空，岗位名称为空");
        }

        if (post.getPersons() != null) {
            mkOrgPost.setFdPersons(post.getPersons());
        } else {
            log.error("岗位webservice接口同步人员为空");
        }
        //岗位同步接口对fdNo字段非空校验
        mkOrgPost.setFdNo("null");
        mkOrgPost.setFdIsAvailable(true);
        mkOrgPost.setFdSourceSystem("601portal");
        log.info("================================岗位参数转换结束================================");
        return mkOrgPost;
    }
}
